package ws;

import javax.jms.JMSException;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

import logic.MapGraphLogic;
import map.MapGraphDatabase;

import analyzer.JMSDataSender;

@WebService
public class DataService {
	
	public void sendData(double[] lons, double[] lats, int[] times){
		int n = lons.length;
		String mes = "";
		for (int i = 0; i < n; ++i){
			mes += lons[i] + " " + lats[i] + " " + times[i] + "|";
		}
		try {
			JMSDataSender.getInstance().sendData(mes);
		} catch (JMSException e){
			e.printStackTrace();
		}
		
	}
	
	public void sendDriverCoordinates(double lon, double lat, String login){
		try {
			JMSDataSender.getInstance().sendDriverCoordinates("" + lon + "|" + lat + "|" + login);
		} catch (JMSException e){
			e.printStackTrace();
		}
	}
	
	public String getTaxi(double lon, double lat){
		MapGraphLogic.getBestDrivers(MapGraphDatabase.getInstance().loadMapGraph().getNearestNode(lat, lon));
		return "";
	}
	
	public static void main(String[] args) {
		System.out.println("WebService HelloService has started");
		Endpoint.publish(
		      "http://localhost:8080/ws/dataservice", new DataService());

		}

}
